//
//  BottomToolBar.m
//  AsyncImages
//
//  Created by Matthew on 11-9-21.
//  Copyright 2011年 develop4u.gr. All rights reserved.
//

#import "BottomToolBar.h"


@implementation BottomToolBar

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) 
    {
        UIImageView *imgView = [[UIImageView alloc] initWithFrame: CGRectMake(0, 0, 320, 50)];
        [imgView setImage:[UIImage imageNamed:@"bottom_bg.png"]];
        imgView.alpha = 0.85;
        imgView.userInteractionEnabled = NO;
        [self addSubview:imgView];
        

        
        /*
         ImageUIButton *workButton;
         ImageUIButton *peopleButton;
         ImageUIButton *jigouButton;
         ImageUIButton *moreButton;
         */
        float scale_val = 1;
        float start_y = 5;
        float start_x = 15;
        float unit_width = 65;
        int i = 0;
        
        newButton = [ImageUIButton buttonWithType:UIButtonTypeCustom];
        newButton.button_id = 0;
        [newButton addButtonWithImageLink:@"new_btn_normal.png" downStatusImgLink:@"new_btn.png"];
        [newButton setXY:start_x+unit_width*i offy:start_y];
        [self buttonScale:newButton scaleVal:scale_val];
        [self addSubview:newButton]; 

        newButtonH = [ImageUIButton buttonWithType:UIButtonTypeCustom];
        newButtonH.button_id = 0;
        [newButtonH addButtonWithImageLink:@"new_btn.png" downStatusImgLink:@"new_btn.png"];
        [newButtonH setXY:start_x+unit_width*i offy:start_y];
        [self buttonScale:newButtonH scaleVal:scale_val];
        [self addSubview:newButtonH]; 
        newButton.hidden = TRUE;
        //newButtonH.hidden = TRUE;
        i++;
        
        workButton = [ImageUIButton buttonWithType:UIButtonTypeCustom];
        workButton.button_id = 1;
        [workButton addButtonWithImageLink:@"work_btn_normal.png" downStatusImgLink:@"work_btn.png"];
        [workButton setXY:start_x+unit_width*i offy:start_y];
        [self buttonScale:workButton scaleVal:scale_val];
        [self addSubview:workButton]; 
        
        workButtonH = [ImageUIButton buttonWithType:UIButtonTypeCustom];
        workButtonH.button_id = 1;
        [workButtonH addButtonWithImageLink:@"work_btn.png" downStatusImgLink:@"work_btn.png"];
        [workButtonH setXY:start_x+unit_width*i offy:start_y];
        [self buttonScale:workButtonH scaleVal:scale_val];
        [self addSubview:workButtonH]; 
        workButtonH.hidden = TRUE;
        i++;
        
        peopleButton = [ImageUIButton buttonWithType:UIButtonTypeCustom];
        peopleButton.button_id = 2;
        [peopleButton addButtonWithImageLink:@"people_btn_normal.png" downStatusImgLink:@"people_btn.png"];
        [peopleButton setXY:start_x+unit_width*i offy:start_y];
        [self buttonScale:peopleButton scaleVal:scale_val];
        [self addSubview:peopleButton]; 

        peopleButtonH = [ImageUIButton buttonWithType:UIButtonTypeCustom];
        peopleButtonH.button_id = 2;
        [peopleButtonH addButtonWithImageLink:@"people_btn.png" downStatusImgLink:@"people_btn.png"];
        [peopleButtonH setXY:start_x+unit_width*i offy:start_y];
        [self buttonScale:peopleButtonH scaleVal:scale_val];
        [self addSubview:peopleButtonH]; 
        peopleButtonH.hidden = TRUE;
        i++;
        
        jigouButton = [ImageUIButton buttonWithType:UIButtonTypeCustom];
        jigouButton.button_id = 3;
        [jigouButton addButtonWithImageLink:@"jigou_btn_normal.png" downStatusImgLink:@"jigou_btn.png"];
        [jigouButton setXY:start_x+unit_width*i offy:start_y];
        [self buttonScale:jigouButton scaleVal:scale_val];
        [self addSubview:jigouButton]; 
        
        jigouButtonH = [ImageUIButton buttonWithType:UIButtonTypeCustom];
        jigouButtonH.button_id = 3;
        [jigouButtonH addButtonWithImageLink:@"jigou_btn.png" downStatusImgLink:@"jigou_btn.png"];
        [jigouButtonH setXY:start_x+unit_width*i offy:start_y];
        [self buttonScale:jigouButtonH scaleVal:scale_val];
        [self addSubview:jigouButtonH]; 
        jigouButtonH.hidden = TRUE;
        i++;
        
        moreButton = [ImageUIButton buttonWithType:UIButtonTypeCustom];
        moreButton.button_id = 4;
        [moreButton addButtonWithImageLink:@"more_btn_normal.png" downStatusImgLink:@"more_btn.png"];
        [moreButton setXY:start_x+unit_width*i offy:start_y];
        [self buttonScale:moreButton scaleVal:scale_val];
        [self addSubview:moreButton]; 

        moreButtonH = [ImageUIButton buttonWithType:UIButtonTypeCustom];
        moreButtonH.button_id = 4;
        [moreButtonH addButtonWithImageLink:@"more_btn.png" downStatusImgLink:@"more_btn.png"];
        [moreButtonH setXY:start_x+unit_width*i offy:start_y];
        [self buttonScale:moreButtonH scaleVal:scale_val];
        [self addSubview:moreButtonH]; 
        moreButtonH.hidden = TRUE;
        
        [newButton  addTarget:self action:@selector(mouseDownProc:) forControlEvents:UIControlEventTouchDown];
        [workButton addTarget:self action:@selector(mouseDownProc:) forControlEvents:UIControlEventTouchDown];
        [peopleButton addTarget:self action:@selector(mouseDownProc:) forControlEvents:UIControlEventTouchDown];
        [jigouButton addTarget:self action:@selector(mouseDownProc:) forControlEvents:UIControlEventTouchDown];
        [moreButton addTarget:self action:@selector(mouseDownProc:) forControlEvents:UIControlEventTouchDown];     
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

-(void) buttonScale:(ImageUIButton *) inUIBtn
                 scaleVal:(float) inScaleVal
{
    inUIBtn.frame = CGRectMake(inUIBtn.frame.origin.x, inUIBtn.frame.origin.y, 
                               inUIBtn.frame.size.width*inScaleVal, inUIBtn.frame.size.height*inScaleVal);
}

-(void) mouseDownProc:(id)sender
{
    newButton.hidden = FALSE;
    workButton.hidden = FALSE;
    peopleButton.hidden = FALSE;
    jigouButton.hidden = FALSE;
    moreButton.hidden = FALSE;
    
    newButtonH.hidden = TRUE;
    workButtonH.hidden = TRUE;
    peopleButtonH.hidden = TRUE;
    jigouButtonH.hidden = TRUE;
    moreButtonH.hidden = TRUE;
 
    ImageUIButton *tempBtn =  sender;
    
    if (tempBtn != Nil) 
    {
        if (tempBtn.button_id == 0) 
        {
            newButton.hidden = TRUE;
            newButtonH.hidden = FALSE;
        }
        else if (tempBtn.button_id == 1) 
        {
            workButton.hidden = TRUE;
            workButtonH.hidden = FALSE;
        }
        else if (tempBtn.button_id == 2) 
        {
            peopleButton.hidden = TRUE;
            peopleButtonH.hidden = FALSE;
        }
        else if (tempBtn.button_id == 3) 
        {
            jigouButton.hidden = TRUE;
            jigouButtonH.hidden = FALSE;   
        }
        else if (tempBtn.button_id == 4) 
        {
            moreButton.hidden = TRUE;
            moreButtonH.hidden = FALSE;
        }
    }

    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"tab_clicked" object:sender];
}


- (void)dealloc
{
    [super dealloc];
}

@end
